<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">



	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<input type="hidden" id="id" name="id">
			<div class='form-group'>
				<label class='col-md-2 control-label'>orderNum</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='orderNum' type='text' name='orderNum' id='orderNum' data-bv-notempty='true' data-bv-notempty-message='orderNum 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>total</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='total' type='text' name='total' id='total' data-bv-notempty='true' data-bv-notempty-message='total 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>integral</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='integral' type='text' name='integral' id='integral' data-bv-notempty='true' data-bv-notempty-message='integral 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>payment</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='payment' type='text' name='payment' id='payment' data-bv-notempty='true' data-bv-notempty-message='payment 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>paymentType</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='paymentType' type='text' name='paymentType' id='paymentType' data-bv-notempty='true' data-bv-notempty-message='paymentType 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>postType</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='postType' type='text' name='postType' id='postType' data-bv-notempty='true' data-bv-notempty-message='postType 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>status</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='status' type='text' name='status' id='status' data-bv-notempty='true' data-bv-notempty-message='status 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>paymentTime</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='paymentTime' type='text' name='paymentTime' id='paymentTime' data-bv-notempty='true' data-bv-notempty-message='paymentTime 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>consignTime</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='consignTime' type='text' name='consignTime' id='consignTime' data-bv-notempty='true' data-bv-notempty-message='consignTime 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>endTime</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='endTime' type='text' name='endTime' id='endTime' data-bv-notempty='true' data-bv-notempty-message='endTime 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>closeTime</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='closeTime' type='text' name='closeTime' id='closeTime' data-bv-notempty='true' data-bv-notempty-message='closeTime 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>shippingName</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='shippingName' type='text' name='shippingName' id='shippingName' data-bv-notempty='true' data-bv-notempty-message='shippingName 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>shippingCode</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='shippingCode' type='text' name='shippingCode' id='shippingCode' data-bv-notempty='true' data-bv-notempty-message='shippingCode 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>freight</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='freight' type='text' name='freight' id='freight' data-bv-notempty='true' data-bv-notempty-message='freight 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>userId</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='userId' type='text' name='userId' id='userId' data-bv-notempty='true' data-bv-notempty-message='userId 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>receiverPhone</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='receiverPhone' type='text' name='receiverPhone' id='receiverPhone' data-bv-notempty='true' data-bv-notempty-message='receiverPhone 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>receiverName</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='receiverName' type='text' name='receiverName' id='receiverName' data-bv-notempty='true' data-bv-notempty-message='receiverName 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>receiverAreaName</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='receiverAreaName' type='text' name='receiverAreaName' id='receiverAreaName' data-bv-notempty='true' data-bv-notempty-message='receiverAreaName 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>afterSalesService</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='afterSalesService' type='text' name='afterSalesService' id='afterSalesService' data-bv-notempty='true' data-bv-notempty-message='afterSalesService 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>invoice</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='invoice' type='text' name='invoice' id='invoice' data-bv-notempty='true' data-bv-notempty-message='invoice 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>num</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='num' type='text' name='num' id='num' data-bv-notempty='true' data-bv-notempty-message='num 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>smallPic</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='smallPic' type='text' name='smallPic' id='smallPic' data-bv-notempty='true' data-bv-notempty-message='smallPic 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>type</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='type' type='text' name='type' id='type' data-bv-notempty='true' data-bv-notempty-message='type 不能为空'>
				</div>
			</div>

		<!--	<div th:each="goods:${goods}">

				<div class='form-group'>
					<label class='col-md-2 control-label'>商品名称</label>
					<div class='col-md-10'>
						<input class='form-control'  th:value="${goods.name}" type='text' readonly="readonly" name='name' id='name' data-bv-notempty='true'>
					</div>
				</div>

				<div class='form-group'>
					<label class='col-md-2 control-label'>商品类型</label>
					<div class='col-md-10'>
						<input class='form-control'   value="123" type='text' readonly="readonly" name='name' id='price' data-bv-notempty='true'>
					</div>
				</div>
			</div>-->
			<div class="widget-body no-padding">
				<table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
					<thead>
					<tr>
						<th>商品名称</th>
						<th>商品价格</th>
					</tr>
					</thead>
					<tbody class="goodsOrderItems">

					</tbody>
				</table>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
						<button class="btn btn-primary" onclick="location.href='goodsOrderList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer','laydate'], function(){
        var layer = layui.layer;
    });

    initData();

    function initData(){
        var id = getUrlParam("id");
        if(id != ""){
            $.ajax({
                type : 'get',
                url : '/goodsOrders/'+id,
                async : false,
                success : function(data) {
                    $('#id').val(data.id);
                    $('#orderNum').val(data.orderNum);
                    $('#total').val(data.total);
                    $('#integral').val(data.integral);
                    $('#payment').val(data.payment);
                    $('#paymentType').val(data.paymentType);
                    $('#postType').val(data.postType);
                    $('#status').val(data.status);
                    $('#createTime').val(data.createTime);
                    $('#updateTime').val(data.updateTime);
                    $('#paymentTime').val(data.paymentTime);
                    $('#consignTime').val(data.consignTime);
                    $('#endTime').val(data.endTime);
                    $('#closeTime').val(data.closeTime);
                    $('#shippingName').val(data.shippingName);
                    $('#shippingCode').val(data.shippingCode);
                    $('#freight').val(data.freight);
                    $('#userId').val(data.userId);
                    $('#receiverPhone').val(data.receiverPhone);
                    $('#receiverName').val(data.receiverName);
                    $('#receiverAreaName').val(data.receiverAreaName);
                    $('#afterSalesService').val(data.afterSalesService);
                    $('#invoice').val(data.invoice);
                    $('#num').val(data.num);
                    $('#smallPic').val(data.smallPic);
                    $('#type').val(data.type);
                    //$('#goodsList').val(data.goodsList);

                }
            });
            /*$.ajax({
                type : 'get',
                url : '/goodsOrders/test/'+id,
                async : false,
                success : function(data) {

                }
            });*/

        }
    }
    var id = getUrlParam("id");
    $.ajax({
        "url" : "/goodsOrders/test/"+id,
        "type":"get",
		"dataType":"text",
        success:function(data){
            JSON.parse(data)
            console.log(JSON.parse(data));
            var list=JSON.parse(data);
            var html=''
            list.forEach(function (item) {
                html+=`<tr>
							<td>${item.name}</td>
							<td>${item.price}</td>
						</tr>`
            })
			$('.goodsOrderItems').html(html)
        }
	})
    /*init();
    function init(){
        var id = getUrlParam("id");
        example =
            $('#dt-table').DataTable({
                "searching": false,
                "processing": false,
                "serverSide" : true,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url" : "/goodsOrders/test/"+id,
                    "type":"get",
                    "data":function(data){
                        console.log(data);
                        /!*d.id = $("#id").val();*!/
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {"data" : "id", "defaultContent" : ""},
                    {"data" : "name", "defaultContent" : ""},
                ],
            } );
    }*/

    function update() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if(!bootstrapValidator.isValid()){
            return;
        }

        var formdata = $("#form").serializeObject();

        $.ajax({
            type : 'put',
            url : '/goodsOrders',
            contentType: "application/json; charset=utf-8",
            data : JSON.stringify(formdata),
            success : function(data) {
                layer.msg("修改成功", {shift: -1, time: 1000}, function(){
                    location.href = "goodsOrderList.html";
                });
            }
        });
    }

</script>
</body>
</html>
